﻿using LinkyPOS.Class;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LinkyPOS
{
    public partial class Hatirlatmalar : Form
    {
        public Hatirlatmalar()
        {
            InitializeComponent();
        }
        linkDataContext ly = new linkDataContext();
        private void Hatirlatmalar_Load(object sender, EventArgs e)
        {
            this.Location = new Point(0, 0);
            this.Size = Screen.PrimaryScreen.WorkingArea.Size;
            label3.Text = DateTime.Now.ToString("d") + "  İçin Hatırlatmalar";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            hatirlatmalar ht = new hatirlatmalar()
            {
            aciklama=txtaciklama.Text,
            durum=1,
            tarih= Convert.ToDateTime(dateTimePicker1.Text),
            };

            ly.hatirlatmalars.InsertOnSubmit(ht);
            ly.SubmitChanges();

            hatirlatmalarilistele();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {

                hatirlatmalar hatirlatmasil = (hatirlatmalar)listView1.FocusedItem.Tag;
                ly.hatirlatmalars.DeleteOnSubmit(hatirlatmasil);
                ly.SubmitChanges();
                listView1.Items.Clear();
                hatirlatmalarilistele();

            }
            catch (Exception d)
            {

                err2 er = new err2(d.ToString(), this.Name);
            }
        }

        private void hatirlatmalarilistele()
        {
            listView1.Items.Clear();

            List<hatirlatmalar> calisanlar = (from emp in ly.hatirlatmalars
                                          where emp.tarih == DateTime.Now
                                          select emp).ToList();
            //List<Employee> emps = (from emp in db.Employees
            //                       select emp).ToList();


            foreach (var item in calisanlar)
            {


                ListViewItem li = new ListViewItem();
                li.Text = item.hatirlatmaID.ToString();
                li.SubItems.Add(item.aciklama.ToString());

                li.SubItems.Add(item.durum.ToString());
                li.SubItems.Add(item.tarih.ToString());

                listView1.Items.Add(li);
                li.Tag = item;
            }



        }
    }
}
